﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using DAL;
using System.Net;
namespace BLL
{
   public class SysAdminManager
    {
       SysAdminService objSysAdminsService = new SysAdminService();
        /// <summary>
        /// 根据登录用户和登录密码调用登录查询
        /// </summary>
        /// <param name="objSysAdmin"></param>
        /// <returns></returns>
        public SysAdmins SysAdminLogin(SysAdmins objSysAdmin)
        {
            //【1】根据用户输入的账号和密码调用后台办法查询
            objSysAdmin = objSysAdminsService.SysAdminLogin(objSysAdmin);
            //判断输出对象是否为空或是否被禁用
            if (objSysAdmin != null && objSysAdmin.AdminStatus == 1)
            {
                //【2】保存登录成功信息
                LoginLogs objLoginLogs = new LoginLogs()
                {
                    LoginId = objSysAdmin.LoginId,
                    SPName = objSysAdmin.AdminName,
                    ServerName = Dns.GetHostName(),
                    LoginTime = DateTime.Now
                };
                //保存当前登录的登录ID（为后面退出系统，把退出时间写入日志做准备）
                objSysAdmin.LoginId = objSysAdminsService.WriteLoginInfo(objLoginLogs);
            }
            return objSysAdmin;
        }
        /// <summary>
        /// 保存退出时间
        /// </summary>
        /// <param name="logId"></param>
        /// <returns></returns>
        public int WriteLogOutInfo(string logId)
        {
            int result = objSysAdminsService.WriteLogOutInfo(logId);
            return result;
        }
    }
}
